package com.fgs.common.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fgs.common.R;
import com.fgs.common.entity.region.RegionInfo;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/10
 * @description
 **/
public class SelectedCityAdapter extends RecyclerArrayAdapter<RegionInfo> {
    public SelectedCityAdapter(Context context) {
        super(context);
    }


    private int inSelectPosition;

    public void setInSelectPosition(int inSelectPosition) {
        this.inSelectPosition = inSelectPosition + 1;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new SelectedCityViewHolder(parent, R.layout.item_select_city);
    }

    public class SelectedCityViewHolder extends BaseViewHolder<RegionInfo> {

        private TextView textView;
        private View lineView;

        public SelectedCityViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            textView = getView(R.id.item_select_city_textView);
            lineView = getView(R.id.item_select_city_lineView);
        }

        @Override
        public void setData(RegionInfo data) {
            super.setData(data);
            if (data.level.equals("1")) {
                if (!TextUtils.isEmpty(data.label)) {
                    textView.setText(data.label);
                    textView.setSelected(true);
                } else {
                    textView.setText("选省份");
                    textView.setSelected(false);
                }
            } else if (data.level.equals("2")) {
                if (!TextUtils.isEmpty(data.label)) {
                    textView.setText(data.label);
                    textView.setSelected(true);
                } else {
                    textView.setText("选城市");
                    textView.setSelected(false);
                }
            } else if (data.level.equals("3")) {
                if (!TextUtils.isEmpty(data.label)) {
                    textView.setText(data.label);
                    textView.setSelected(true);
                } else {
                    textView.setText("选地区");
                    textView.setSelected(false);
                }
            }

            if (inSelectPosition == getDataPosition()) {
                lineView.setVisibility(View.VISIBLE);
            } else {
                lineView.setVisibility(View.GONE);
            }

        }
    }
}
